package com.scuec.groupfive.Controller;

import com.scuec.groupfive.entity.UserInfo;
import com.scuec.groupfive.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/list")
    //http://localhost:8081/user/list
    public List<UserInfo> getUserList() {
        return userService.getUserList();
    }

    @GetMapping("/detail/{userId}")
    public UserInfo getUserById(@PathVariable Integer userId) {
        return userService.getUserById(userId);
    }

    @PutMapping("/status")
    //http://localhost:8080/user/list/status
    public int updateUserStatus(
            @RequestParam Integer userId,
            @RequestParam Integer status) {
        return userService.updateUserStatus(userId, status);
    }

    @PutMapping("/update")
    public int updateUserInfo(@RequestBody UserInfo userInfo) {
        return userService.updateUserInfo(userInfo);
    }
}